﻿using System.Xml.Linq;
using IDeal.Models;
using IDeal.Services;

namespace IDeal.Serialization
{
    internal class TransactionResponseXmlReader : XmlMessageReader<TransactionResponse>
    {
        public TransactionResponseXmlReader(IIDealServices iDealServices) : base(iDealServices)
        {
        }

        protected override void ParseRootElement(TransactionResponse instance, XElement rootElement)
        {
            var transactionElement = rootElement.Element(Ns + "Transaction");
            instance.AcquirerId = rootElement.Element(Ns + "Acquirer").Element(Ns + "acquirerID").Value;
            instance.IssuerAuthenticationUrl = rootElement.Element(Ns + "Issuer").Element(Ns + "issuerAuthenticationURL").Value;
            instance.TransactionId = transactionElement.Element(Ns + "transactionID").Value;
            instance.PurchaseId = transactionElement.Element(Ns + "purchaseID").Value;
        }
    }
}
